/*
@Author   : Uyynot
@Email    : uyynot@qq.com
@Time     : 2023/8/23 17:41
@File     : user.go
@Project  : web_scaff
@Desc     :
*/
package user

import (
	"fmt"
	"web_scaff/dao"
	dao_user "web_scaff/dao/user"
	"web_scaff/models"
	"web_scaff/pkg/aes"
	"web_scaff/pkg/snowflake"
)

type SearchData struct {
	Page     int    `form:"page"`      // 第几页
	PageSize int    `form:"page_size"` // 每页显示条数
	Username string `form:"username"`  // 用户名
	Phone    string `form:"phone"`     // 手机号
}

func Create(u *models.User) error {
	//生成uid
	u.Uid = snowflake.GenId()
	//加密手机号
	u.Phone, _ = aes.AesClient.Encrypt(u.Phone)
	fmt.Println("user:", u)
	return dao.CreateUser(u)
}

func List(req *SearchData) (total int64, users []models.User, err error) {
	whereData := dao_user.WhereData(*req)
	return dao_user.List(&whereData)
}

func Retrive(id string) (user models.User, err error) {
	return dao_user.Retrive(id)
}
